package com.tanhua.server.service;

import com.itheima.dubbo.api.UserLocationApi;
import com.tanhua.model.vo.ErrorResult;
import com.tanhua.server.exception.BusinessException;
import com.tanhua.server.interceptor.UserThreadLocal;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @Author Pan Rundong
 * @Date 2023-03-06 10:31
 * @Desc 地理功能Service
 */
@Service
public class BaiduService {
    @DubboReference
    private UserLocationApi userLocationApi;

    /**
     * 上报地理位置
     *
     * @param latitude
     * @param longitude
     * @param addr
     * @return void
     * @Author Pan Rundong
     */
    public void location(Double latitude, Double longitude, String addr) {
        //1.获取当前用户
        Long userId = UserThreadLocal.getUserId();

        //2.调用api
        Boolean flag = userLocationApi.updateLocation(userId, longitude, latitude, addr);

        //3.如果失败抛出异常
        if (!flag) {
            throw new BusinessException(ErrorResult.error());
        }
    }
}
